package me.zk.practice1.s;

/**
 * @Author: zhang kai
 * @Date: 2023/05/05
 * @Description:
 */
public class S10 {
    public static void main(String[] args) {
        System.out.println(canPlaceFlowers(new int[]{1,0,0,0,1,0,0}, 2));
    }
    public static boolean canPlaceFlowers(int[] flowerbed, int n) {

        //可以种多少 - 已经种 >= n true
       int i = 0;
       while (i < flowerbed.length && n > 0) {
           if (flowerbed[i] == 1) {
               i+=2;
           } else if (i== flowerbed.length -1 || flowerbed[i+1] == 0) {
               i+=2;
               n--;
           } else {
               i+=3;
           }
       }
        return n<=0;
    }
}
